<template>
  <Dialog
    :visible="addVisible"
    title="结算"
    :top="'25vh'"
    :width="480"
    @close="addVisible = false"
  >
    <div style="padding: 5px" v-if="addVisible">
      <h1>确认结算该采购单吗？</h1>
      <el-form :model="formData" label-width="60px"  :labelPosition="'left'">
        <el-form-item label="备注：">
          <el-input v-model="formData.settleRemark" style="border: 1px solid #f5f7fa;" type="textarea" />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <el-button @click="handleSubmit" type="primary">确 定</el-button>
      <el-button @click="addVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>

<script setup lang="ts">
import type { PurchaseInfo, PurchasePagination } from '@/types/purchase';
import { settlePurchase } from '@/api/purchase';
const addVisible = ref(false);
import stores from '@/store';

const formData = ref<PurchaseInfo>({
  orderId: '',
  settleRemark: '',
}); 
defineExpose<{
  open: (menu: number) => void;
}>({
  open: (menu: number) => {
    formData.value.orderId = menu;
    formData.value.settleRemark = ''
    addVisible.value = true;
  },
});

const handleSubmit = async () => {
  let res = await settlePurchase(formData.value);
  if (res.code == '200') {
    ElMessage({
      type: 'success',
      message: res.msg,
      duration: 2000,

    });
    closeDrawer();
  } else {
  }
};
const emit = defineEmits(['closeDrawer']);
const closeDrawer = () => {
  addVisible.value = false;
  emit('closeDrawer');
};
</script>
<style lang="scss" scoped>
  h1{
    font-family: Microsoft YaHei, Microsoft YaHei;
    font-weight: 400;
    font-size: var(--el-form-label-font-size);
    color: var(--el-text-color-regular);
    margin-bottom: 20px;
    text-align: left;
    font-style: normal;
    text-transform: none;
}
</style>
